package com.xq.model.mapper;

import com.xq.model.dto.PostDataTransferDTO;
import com.xq.model.entity.TBaseStationState;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 站点状态信息表 Mapper 接口
 * </p>
 *
 * @author xu
 * @since 2021-08-31
 */
public interface TBaseStationStateMapper extends BaseMapper<TBaseStationState> {

    /**
     * 获取最大访问轮次
     * @return
     */
    @Select(value = "SELECT max(request_num) FROM  t_base_station_state")
    Integer selectMaxRequestNum();

    /**
     * 根据数据类型统计站点数量
     * @return
     */
    @Select(value = "SELECT \n" +
            "\tStation_Id_C as stationIdC,\n" +
            "\tsum(case when id then 1 else 0 end) as shouldNum,\n" +
            "\tsum(case when state_type ='1' then 1 else 0 end) as inNum,\n" +
            "\tsum(case when state_type ='2' then 1 else 0 end) as missNum,\n" +
            "\tsum(case when state_type ='3' then 1 else 0 end) as overNum\n" +
            "FROM t_base_station_state\n" +
            "GROUP BY Station_Id_C")
    List<PostDataTransferDTO> countDataTransfer();
}
